package com.meitianhui.convenitenbuy.module.store.presenter;

import com.google.gson.Gson;
import com.meitianhui.convenitenbuy.base.BaseResponse;
import com.meitianhui.convenitenbuy.config.InfoProvider;
import com.meitianhui.convenitenbuy.http.ResponseObserver;
import com.meitianhui.convenitenbuy.module.store.contract.PreferentialActivityContract;
import com.meitianhui.convenitenbuy.module.store.http.StoreApiDataSource;
import com.meitianhui.convenitenbuy.module.store.model.CouponCardInfo;
import com.meitianhui.convenitenbuy.module.store.ui.activity.PreferentialActivityActivity;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/27.
 */

public class PreferentialActivityPresenter implements PreferentialActivityContract.Presenter {

    private PreferentialActivityActivity mContext;
    private final PreferentialActivityContract.View mView;

    public PreferentialActivityPresenter(PreferentialActivityContract.View view,
                                         PreferentialActivityActivity context) {
        this.mView = view;
        this.mContext = context;
    }

    @Override
    public void attachView(Object view) {
    }

    @Override
    public void detachView() {
    }

    @Override
    public void getCouponCard(String storeId) {
        Map<String, String> params = new HashMap<>();
        params.put("stores_id", storeId);
        String paramJson = new Gson().toJson(params);
        StoreApiDataSource.getInstance()
                .getCouponCard(InfoProvider.getAppToken(mContext),
                        "goods.couponListFindForConsumer", paramJson)
                .subscribe(new ResponseObserver<BaseResponse<CouponCardInfo>>(mContext, true) {
                    @Override
                    public void onSuccess(BaseResponse<CouponCardInfo> response) {
                        mView.getCouponCardSuccess(response.data);
                    }
                });
    }

}
